package com.example.system.controller;

import com.example.core.controller.BaseController;
import com.example.core.domain.R;
import com.example.core.domain.TableDataInfo;
import com.example.system.domain.exam.Dto.ExamAddDTO;
import com.example.system.domain.exam.Dto.ExamEditDTO;
import com.example.system.domain.exam.Dto.ExamQueryDTO;
import com.example.system.domain.exam.Dto.ExamQuestionDTO;
import com.example.system.domain.exam.VO.ExamDetailVO;
import com.example.system.service.impl.ExamServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    private ExamServiceImpl examService;

    @GetMapping("/list")
    public TableDataInfo list( ExamQueryDTO examQueryDTO) {
        return getDataTable( examService.list(examQueryDTO));
    }

    @PostMapping("/add")
    public R<Void> add(@RequestBody ExamAddDTO examAddDTO) {
        return toResult( examService.add(examAddDTO));
    }

    @PostMapping("/question/add")
    public R<Void>  questionAdd(@RequestBody ExamQuestionDTO examQuestionDTO){
        return toResult(examService.questionAdd(examQuestionDTO));
    }

    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId){
        return R.ok(examService.detail(examId));
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO){
       return toResult( examService.edit(examEditDTO));
    }

    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId,Long questionId){
        return toResult(examService.questionDelete(examId,questionId));
    }

    @DeleteMapping("/delete")
    public R<Void> delete(Long examId){
        return toResult(examService.delete(examId));
    }

    @PutMapping("/publish")
    public R<Void> publish(Long examId){
        return toResult(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId){
        return toResult(examService.cancelPublish(examId));
    }
}
